package com.csxy.ljr.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.csxy.ljr.entity.EduTeacher;
import com.csxy.ljr.entity.vo.TeacherQuery;
import com.csxy.ljr.mapper.EduTeacherMapper;
import com.csxy.ljr.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class EduTeacherServiceImpl extends ServiceImpl<EduTeacherMapper, EduTeacher> implements EduTeacherService {
    @Autowired
    private EduTeacherMapper eduTeacherMapper;

    @Override
    public Page<EduTeacher> pageListTeacher(long page, long limit) {
        Page<EduTeacher> mypage = new Page<>(page, limit);
        Page<EduTeacher> eduTeacherPage = eduTeacherMapper.selectPage(mypage, null);
        return eduTeacherPage;
    }

    @Override
    public void pageQuery(Page<EduTeacher> pageParam, TeacherQuery teacherQuery) {
        QueryWrapper<EduTeacher> queryWrapper = new QueryWrapper<>();
        if (teacherQuery == null) {
            eduTeacherMapper.selectPage(pageParam, null);
        }
        if (teacherQuery.getName() != null && !"".equals(teacherQuery.getName())) {
            queryWrapper.like("name", teacherQuery.getName());
        }
        if (teacherQuery.getLevel() != null && !"".equals(teacherQuery.getLevel())) {
            queryWrapper.eq("level", teacherQuery.getLevel());
        }
        if (teacherQuery.getBegin() != null && !"".equals(teacherQuery.getBegin())) {
            queryWrapper.ge("gmt_create", teacherQuery.getBegin());
        }
        if (teacherQuery.getEnd() != null && !"".equals(teacherQuery.getEnd())) {
            queryWrapper.le("gmt_create", teacherQuery.getEnd());
        }
        eduTeacherMapper.selectPage(pageParam, queryWrapper);
    }

}